<html>
    <head>
        <style>
            body {
                padding: 0;
                margin: 0;
            }

            #container {
                width: 100px;
                height: 100px;
            }

            #fixed {
                position: fixed;
                top: 0;
                left: 0;
                width: 500px;
                height: 100px;
                background: #00cc88;
                display: flex;
                align-items: flex-start;
            }

            #child {
                width: 100px;
                height: 100px;
                background: #0077ff;
            }

            #trigger-overflow {
                width: 1px;
                height: 1px;
                position: absolute;
                top: 2000px;
                left: 2000px;
            }

            [data-layout-correct="false"] {
                background: #dd1144 !important;
                opacity: 0.5;
            }
        </style>
    </head>
    <body>
        <div id="container">
            <div id="fixed">
                <div id="child"></div>
            </div>
        </div>
        <div id="trigger-overflow"></div>

        <script type="module" src="/src/imports/projection.js"></script>
        <script type="module" src="/src/imports/script-assert.js"></script>
        <script type="module" src="/src/imports/script-undo.js"></script>
        <script type="module">
            const { createNode } = window.Undo
            const {
                matchViewportBox,
                matchVisibility,
                matchOpacity,
                addPageScroll,
            } = window.Assert
            const { frame } = window.Projection

            const fixed = document.getElementById("fixed")
            const fixedProjection = createNode(fixed, undefined, {
                layoutScroll: true,
                layout: true,
            })
            const fixedOrigin = fixed.getBoundingClientRect()

            const child = document.getElementById("child")
            const childProjection = createNode(child, fixedProjection)
            const childOrigin = child.getBoundingClientRect()

            childProjection.willUpdate()
            fixedProjection.willUpdate()

            const scrollDistance = 100
            window.scrollTo(scrollDistance, scrollDistance)
            fixed.style.justifyContent = "flex-end"
            fixed.style.top = "50px"
            fixed.style.left = "50px"

            fixedProjection.root.didUpdate()

            setTimeout(() => {
                matchViewportBox(fixed, fixedOrigin)
                matchViewportBox(child, {
                    top: 0,
                    left: 0,
                    right: 100,
                    bottom: 100,
                })
            }, 50)
        </script>
    </body>
</html>
